package com.chunfeng.mypen.controller;

import com.chunfeng.mypen.entity.File;
import com.chunfeng.mypen.result.JsonRequest;
import com.chunfeng.mypen.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文件Controller
 *
 * @author by 春风能解释
 * <p>
 * 2023/11/22
 */
@RestController
@RequestMapping("/file")
@Api(value = "文件控制层", tags = "文件操作访问接口")
public class FileController {
    /**
     * 文件业务层
     */
    @Autowired
    private FileService fileService;


    /**
     * 分类查询文件
     *
     * @param current 当前页
     * @param size    每页长度
     * @param file    分类
     * @return JSON
     */
    @GetMapping
    @ApiOperation(value = "分类筛选文件信息")
    public JsonRequest<List<File>> lookFile(
            @ApiParam(value = "当前页数", required = true)
            @RequestParam Integer current,
            @ApiParam(value = "每页长度", required = true)
            @RequestParam Integer size,
            @ApiParam(value = "条件", required = true)
            File file) {
        return fileService.lookAllFile(current, size, file);
    }


    /**
     * 新增一条文件数据
     *
     * @param file 文件信息
     * @return JSON
     */
    @PostMapping
    @ApiOperation(value = "新增一条文件信息")
    public JsonRequest<Integer> insertOneFile(
            @ApiParam(value = "待添加的文件信息", required = true)
            @RequestBody File file) {
        return fileService.insertOneFile(file);
    }

    /**
     * 修改一条文件数据
     *
     * @param file 待修改的文件信息
     * @return JSON
     */
    @PutMapping
    @ApiOperation(value = "修改一条文件信息")
    public JsonRequest<Integer> updateOneFile(
            @ApiParam(value = "待修改的文件信息", required = true)
            @RequestBody File file) {
        return fileService.updateFile(file);
    }

    /**
     * 批量删除文件
     *
     * @param fileId 文件ID
     * @return JSON
     */
    @DeleteMapping
    @ApiOperation(value = "批量删除文件信息")
    public JsonRequest<Integer> deleteFiles(
            @ApiParam(value = "待删除的文件ID", required = true)
            @RequestBody List<String> fileId) {
        return fileService.deleteFile(fileId);
    }
}
